package com.jg.controller;

import com.jg.comm.Page;
import com.jg.entity.Book;
import com.jg.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 86130
 * @version 1.0
 * @description: TODO
 * @date 2025/9/2 下午4:45
 */
@RestController
@RequestMapping("/book")
@CrossOrigin
public class BookController {
    @Autowired
    BookService bookService;

    // 获取分页列表
    //@RequestMapping(value = "/page",method = RequestMethod.GET)
    @GetMapping("/page")
    public Page<Book> getBookPage(String bookName, String author, Integer pageNum, Integer pageSize) {
        return bookService.getBookPage(bookName, author, pageNum, pageSize);
    }

    @PostMapping( "/add")
    public String addBook(@RequestBody Book book) {
        return bookService.addBook(book);
    }

    @DeleteMapping("/delete/{id}")
    public String deleteBook(@PathVariable Integer id) {
        return bookService.deleteBook(id);
    }

    @PutMapping("/update")
    public String updateBook(@RequestBody Book book) {
        return bookService.updateBook(book);
    }
}
